package lensfield;

import java.io.File;
import java.util.Arrays;

import org.apache.log4j.Logger;
/**
import org.apache.maven.embedder.Configuration;
import org.apache.maven.embedder.ConfigurationValidationResult;
import org.apache.maven.embedder.DefaultConfiguration;
import org.apache.maven.embedder.MavenEmbedder;
import org.apache.maven.embedder.MavenEmbedderException;
import org.apache.maven.execution.DefaultMavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionRequest;
*/

/**
 * Utility class for calling Maven.
 * 
 * @author ned24
 *
 */
public class MavenUtils {

    private static final Logger LOG = Logger.getLogger(MavenUtils.class);

    /**
     * Runs a set of Maven goals (in the order provided) for the Maven project
     * in <code>projectDir</code>. For instance, calling:
     *
     * <code>
     * MavenUtils.runGoals(new File("c:/projects/foo"), {"clean", "compile"});
     * </code>
     *
     * will clean and then compile the project in c:/projects/foo.
     *
     * @param projectDir - directory containing the Maven project that the goals
     * will be run on.
     * @param goals - the Maven goals to run.  These are called in the order
     * provided in the array.
     */
    public static void runGoals(File projectDir, String[] goals) {
    	/*
        Configuration configuration = new DefaultConfiguration().setClassLoader(Thread.currentThread().getContextClassLoader());
        ConfigurationValidationResult validationResult = MavenEmbedder.validateConfiguration(configuration);
        if (validationResult.isValid()) {
            try {
                MavenEmbedder embedder = new MavenEmbedder(configuration);
                MavenExecutionRequest request = new DefaultMavenExecutionRequest().setBaseDirectory(projectDir).setGoals(Arrays.asList(goals));
                embedder.execute(request);
            } catch (MavenEmbedderException e) {
                LOG.warn("Failure running Maven goals due to: " + e.getMessage());
            }
        } else {
            LOG.warn(validationResult.getUserSettingsException().getMessage());
        }
        */
    }

    /**
     * Main method meant for demonstration of use.
     *
     */
    public static void main(String[] args) {
        File dir = new File("c:/workspace/lensfield-shortgaussian-example/webapp");
        String[] goals = {"clean", "package"};
        runGoals(dir, goals);
    }
}
